<template>
  <CommonDialog v-model="visible" title="导入元数据" :width="500" submit-text="立即导入" @submit="submit"
    @cancel="cancel">
    <Form ref="formEl" :model="formData" :rules="rules">
      <div class="flex_form_item">
        <FormItem label="数据文件" prop="cusfile">
          <Upload :before-upload="handleUpload" action="//jsonplaceholder.typicode.com/posts/">
            <Button icon="ios-cloud-upload-outline">上传数据文件</Button>

            <template #tip>
              <span class="tips">(data格式文件)</span>
            </template>
          </Upload>
        </FormItem>
      </div>
    </Form>
  </CommonDialog>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { Message } from 'view-ui-plus'

import { metadata } from '@/api/modules/modelSetting'

const emit = defineEmits(['cancel', 'submit'])

// 是否打开弹窗
const visible = ref(true)

// 加载状态
const loading = ref(false)
// 表单元素ref
const formEl = ref(null)
// 表单字段
const formData = ref({
  cusfile: ''
})

// 表单校验条件
const rules = ref({
  cusfile: [
    {
      required: true,
      message: '请上传用户账号数据文件',
      trigger: 'blur'
    }
  ]
})
/**
 * 提交表单
 */
const submit = async () => {
  let valid = await formEl.value.validate((valid, fild) => (valid ? valid : fild))
  if (!valid) return

  loading.value = true
}

/**
 * 取消表单
 */
const cancel = () => {
  visible.value = false
  emit('cancel')
}

const getDetailData = () => {}

/**
 * 初始化对话框
 */
const initDialog = id => {
  // 显示对话框
  visible.value = true
}

defineExpose({
  initDialog
})
</script>

<style scoped lang="scss">
.tips{
  margin-left: 30px;
}
</style>